/**
 * Copyright 2016 JustWayward Team
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ecy.quadratic.manager;

import android.text.TextUtils;

import com.ecy.quadratic.beans.user.User;
import com.ecy.quadratic.reader.utils.SharedPreferencesUtil;
import com.google.gson.Gson;

/**
 * @author yuyh.
 * @date 2016/9/23.
 */
public class LoginManager {

    private volatile static LoginManager manager;

    public static LoginManager getInstance() {
        return manager != null ? manager : (manager = new LoginManager());
    }


    public void saveUser(User user) {
        SharedPreferencesUtil.getInstance().putString("currentUser", new Gson().toJson(user, User.class));
    }

    public User getUser() {
        String userJson = SharedPreferencesUtil.getInstance().getString("currentUser", null);
        User user = null;
        if (!TextUtils.isEmpty(userJson)) {
            Gson gson = new Gson();
            user = gson.fromJson(userJson, User.class);
        }
        return user;
    }

    public String getUserJson() {
        String userJson = SharedPreferencesUtil.getInstance().getString("currentUser", null);
        return userJson;
    }


}
